home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / dbdoc.zip / QBEDOC.C < prev    next >
C/C++ Source or Header  |  1991-11-02  |  3KB  |  77 lines

  1. /****************************************************************************/
  2. /*                          qbedoc.c                                        */
  3. /*                                                                          */
  4. /*  Program to read the ASCII portion of a .qbe file.                       */
  5. /*                                                                          */
  6. /****************************************************************************/
  7.  
  8. #include <ctype.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. /****************************************************************************/
  13. /*                          definitions                                     */
  14. /****************************************************************************/
  15.  
  16. /****                      ****  values  ****                            ****/
  17.  
  18. #define CTRLZ         0x1A      /* end-of-ASCII marker                      */
  19. #define MAXSTRING         1024
  20.  
  21. /****              ****  function prototypes  ****                       ****/
  22.  
  23. int qbedoc ( char *filespec );
  24.  
  25. /*      globals             */
  26.  
  27. extern char message[], tempbuff[];
  28.  
  29. /****************************************************************************/
  30. /*                              qbedoc                                      */
  31. /*  Principal routine of this module.  Reads and prints the ASCII data of   */
  32. /*  the qbe file identified by the filespec passed.                         */
  33. /*  Parameters:                                                             */
  34. /*      char *filespec  -- pointer to specification of the .qbe file        */
  35. /*  Returns:                                                                */
  36. /*      0 if successful, 1 if any error occurs.                             */
  37. /*  Side effects:                                                           */
  38. /*      Uses message and printit().                                         */
  39. /*                                                                          */
  40. /****************************************************************************/
  41.  
  42. int qbedoc ( char *filespec )
  43. {
  44.     FILE *qbefile;
  45.     char qbehead[25];
  46.     int c;
  47.  
  48. /*  open file and check for .qbe type       */
  49.  
  50.     if ( ( qbefile = fopen( filespec, "rb" ) ) == NULL )
  51.     {
  52.         sprintf( message, "Can't open file %s", filespec );
  53.         return 1;
  54.     }
  55.  
  56.     strcpy( qbehead, "* dBASE IV .QBE file 8" );
  57.  
  58.     if ( strcmp( fgets( tempbuff, strlen(qbehead) + 1, qbefile ), qbehead ) )
  59.     {
  60.         fclose ( qbefile );
  61.         strcpy( message, "Not a valud .QBE file" );
  62.         return 1;
  63.     }
  64.  
  65.     while ( ( c = fgetc( qbefile ) ) != CTRLZ )
  66.     {
  67.         ungetc( c, qbefile );
  68.         fgets( message, MAXSTRING, qbefile );
  69.         *( strchr( message,'\r' ) ) = '\0';
  70.         printit( 0 );
  71.     }
  72.     fclose ( qbefile );
  73.     return 0;
  74. }
  75.  
  76. /*   EOF  */
  77.